﻿using System;
using System.Windows.Controls;
using System.Windows.Data;

namespace LpbPrj.Client.Tools.Converter
{
    public class TreeViewLineConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            TreeViewItem item = (TreeViewItem)value;
            int param = int.Parse(parameter.ToString());
            ItemsControl ic = ItemsControl.ItemsControlFromItemContainer(item);
            int index = ic.ItemContainerGenerator.IndexFromContainer(item);
            return param == 0 ? index == 0 : index == (ic.Items.Count - 1);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return false;
        }
    }
}
